import Cookie from 'js-cookie'

export default {
    namespaced:true,
    state:{
        token:'',
        user:'',
        username:'',
        date:''
    },
    mutations:{
        setToken(state, val){
            state.token = val
            Cookie.set('token', val)
        },
        getToken(state){
            state.token = state.token || Cookie.get('token')
        },
        clearToken(state){
            state.token = ''
            Cookie.remove('token')
        },
        currentUser(state,val){
            val.len.length > 2 ? state.user='超级管理员' : state.user='普通用户'
            state.username = val.username
            state.date = val.date
        },
    }
}